<template>
	<view>
		<view class="uesr-info">
			<image :src="portrait" class="wx-portrait"></image>
			<view v-if="!nickname" class="wx-nickname" @click="login()">点击登录</view>
			<view v-if="nickname" class="wx-nickname">{{ nickname }}</view>
		</view>
		<template v-if="nickname">
			<view  class="card-item" @click="personal()">
				<image class="left" src="/static/images/personal.png"></image>
				个人信息
				<image class="right" src="/static/images/right.png"></image>
			</view>
			<navigator url="/pages/like/like" class="card-item">
				<image class="left" src="/static/images/like.png"></image>
				我的点赞
				<image class="right" src="/static/images/right.png"></image>
			</navigator>
			<navigator url="/pages/collect/collect" class="card-item">
				<image class="left" src="/static/images/collect.png"></image>
				我的收藏
				<image class="right" src="/static/images/right.png"></image>
			</navigator>
			<navigator url="/pages/me/member" class="card-item">
				<image class="left" src="/static/images/aboutUs.png"></image>
				关于我们
				<image class="right" src="/static/images/right.png"></image>
			</navigator>
			<view  class="card-item" @click="logout()">
				<image class="left" src="/static/images/logout.png"></image>
				退出登录
				<image class="right" src="/static/images/right.png"></image>
			</view>
		</template>
	</view>
</template>

<script>
	import login from '@/common/login.js'
	export default {
		data() {
			return {
				nickname: '',
				portrait: '/static/images/defult-portrait.png'
			}
		},
		onShow() {
			if (uni.getStorageSync('user_id')) {
				this.nickname = uni.getStorageSync('nickname');
				this.portrait = uni.getStorageSync('portrait');
			}
		},
		onLoad() {
			login.getAuth((res) => {
				this.setUserInfo(res.data)
			},() => {
			});
		},
		methods: {
			setUserInfo(data) {
				this.nickname = data.nickname;
				this.portrait = data.portrait;
			},
			login() {
				login.login((res) => {
					this.setUserInfo(res.data)
				})
			},
			clearData() {
				this.nickname = '';
				this.portrait = '/static/images/defult-portrait.png';
			},
			logout() {
				uni.showLoading({
					'title': '退出登录中...'
				})
				setTimeout(() => {
					uni.clearStorage();
					this.clearData()
					uni.showToast({
						'title': '退出登录成功'
					})
				}, 500);
			},
			personal() {
				uni.showToast({
					'title': '功能待完善...',
					'icon': 'none'
				})
			}
		}
	}
</script>

<style>
	@import url("/static/css/me.css");
</style>
